package com.right.health.app.net;

import com.magics.http.model.HttpParams;
import com.right.health.app.app.App;
import com.right.health.app.bean.BloodPressureDetailResponse;
import com.right.health.app.bean.BloodPressureResponse;
import com.right.health.app.bean.BloodSugarResponse;

import org.json.JSONException;
import org.json.JSONObject;

/*
 * Created by hopeliao on 2019-12-08
 *
 */
public class HouseholdApi extends IBaseApi {

    public void addBloodPressure(String highpressure, String lowvoltage, String pulse) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("highpressure", highpressure); //收缩压
            jsonObject.put("lowvoltage", lowvoltage); //舒张压
            jsonObject.put("pulse", pulse); //心率

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        doPostJson(HttpConstants.API_ADD_BLOOD_PRESSURE, params, null);
    }

    public void getLatestBloodPressure() {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            PageUtil.addPageJson(jsonObject, 1, 1);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_LIST_PRESSURE, params, BloodPressureResponse.class);
    }

    public void getBloodPressureByType(String daytype) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("daytype", daytype);
            PageUtil.addPageJson(jsonObject, 1, 1000);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_LIST_PRESSURE, params, BloodPressureResponse.class);
    }

    public void getBloodPressureList(int pageNo) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            PageUtil.addPageJson(jsonObject, pageNo);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_LIST_PRESSURE, params, BloodPressureResponse.class);
    }

    public void getBloodPressureDetail(String id) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("bloodPressureid", id);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_LIST_PRESSURE_DETAIL, params, BloodPressureDetailResponse.class);
    }

    public void deleteBloodPressure(String id) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("bloodPressureid", id);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_DELETE_PRESSURE, params, BloodPressureDetailResponse.class);
    }

    public void addBloodSugar(float value, int type, int mealType) {
        HttpParams params = new HttpParams();

        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("sugarvalue", value);
            jsonObject.put("sugartimetype", type);
            jsonObject.put("foodstatus", mealType);

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        doPostJson(HttpConstants.API_ADD_SUGAR, params, null);
    }

    public void getLatestBloodSugar() {

        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
//            PageUtil.addPageJson(jsonObject, 1, 1000);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_BLOOD_SUGAR_LATEST, params, BloodSugarResponse.class);
    }

    public void getBloodSugarByType(String type) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("daytype",type);
            PageUtil.addPageJson(jsonObject, 1, 1000);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_BLOOD_SUGAR_LIST, params, BloodSugarResponse.class);
    }
}
